﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Xmobile.UserControls.AppDetails
{
    public partial class ucAppDetails : System.Web.UI.UserControl
    {
        public int AppID = 0;
        int CatID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["cat_id"] != null && Request.QueryString["cat_id"].ToString() != "")
            {
                CatID = Convert.ToInt32(Request.QueryString["cat_id"]);
            }
            else
            {
                if (CatID == 0)
                {
                    Response.Redirect("/");
                }
            }

            if (Request.QueryString["appid"] != null && Request.QueryString["appid"].ToString() != "")
            {
                AppID = Convert.ToInt32(Request.QueryString["appid"]);
            }
            else
            {
                if (AppID == 0)
                {
                    Response.Redirect("/");
                }
            }

            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            
            DataTable dt = new DataTable();
            dt = Xmobile.BO.Apps.AppsBO.Apps_Select_by_AppID(AppID);
            if (dt != null && dt.Rows.Count > 0)
            {
                imgApp.ImageUrl = dt.Rows[0]["AppImage"].ToString();
                ltrAppName.Text = dt.Rows[0]["AppName"].ToString();
                if(dt.Rows[0]["AppPartner"].ToString().Trim()=="")
                {
                    ltrPartner.Text = "Sunnet";
                }
                else
                {
                    ltrPartner.Text = dt.Rows[0]["AppPartner"].ToString();
                }
                ltrAppPublish.Text = dt.Rows[0]["AppPublish"].ToString();
                ltrAppContent.Text = dt.Rows[0]["AppContent"].ToString();
                ltrSize.Text = dt.Rows[0]["AppSize"].ToString();
                ltrDownloadCount.Text = dt.Rows[0]["AppDownloadCount"].ToString();
                if (dt.Rows[0]["AppCategory"].ToString() != "")
                    ltrAppCategory.Text = dt.Rows[0]["AppCategory"].ToString();
                else
                    ltrAppCategory.Text = "Giải trí";
            }
            
        }
    }
}